import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {HttpClient} from '@angular/common/http';
import {Router} from '@angular/router';
import {AppService} from '../../service/app/app.service';

@Component({
  selector: 'app-send-email',
  templateUrl: './send-email.component.html',
  styleUrls: ['./send-email.component.css']
})
export class SendEmailComponent implements OnInit {
  validateForm: FormGroup;
  errorMessage: string;
  showMessage = false;
  sendImg = require('../../../assets/restpassword.png');
  constructor(private fb: FormBuilder,
              private appService: AppService,
              private router: Router) {
    this.validateForm = this.fb.group({
      email: [null, [Validators.required]],
    });
  }
  sendEmail() {
    this.appService.post(this.appService.urls.register, this.validateForm.value).subscribe((resp: any) => {
      if (resp.ret === 0) {
        this.showMessage = true;
        this.errorMessage = resp.msg;
      } else {
        this.router.navigate(['rest']).catch();
      }
    });
  }
  ngOnInit() {
  }
  enterRegister() {
    this.router.navigate(['register']).catch();
  }
  enterLogin() {
    this.router.navigate(['login']).catch();
  }

}
